import axios from 'axios';
import store from '../vuex/store'
const service = axios.create({
  baseURL: 'http://localhost:18088'
})
// request 拦截器
// 可以自请求发送前对请求做一些处理
// 比如统一加token，对请求参数统一加密
service.interceptors.request.use(config => {
  if (!config.data) {
    config.data = true // 解决请求没有参数时添加不上Content-Type问题
  }
  console.log(sessionStorage.getItem("token"))
  config.headers['token'] = store.state.UserToken;
  return config
}, error => {
  return Promise.reject(error)
});
service.interceptors.response.use(
    response => {
      if (response.code !== '200') {
        return response.data;
      } else {
        return response;
      }
    },
    error => {
         console.log(error)
      return Promise.reject();
    }
);
export default service